package com.wonderGirls.swGirls2.offer;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.wonderGirls.swGirls2.MainActivity;

public class OfferHelper
{
	private static IOffer offerClient = new DianJoyOfferUtil();

	public static void init(final Context context)
	{
		MainActivity.instance.runOnUiThread(new Runnable()
		{
			@Override
			public void run()
			{
				offerClient.init(context);
			}
		});
	}

	public static void updateCoins(final Context context)
	{
		MainActivity.instance.runOnUiThread(new Runnable()
		{
			@Override
			public void run()
			{
				offerClient.updateCoins(context);
			}
		});
	}

	public static void dispose(final Context context)
	{
		MainActivity.instance.runOnUiThread(new Runnable()
		{
			@Override
			public void run()
			{
				offerClient.dispose(context);
			}
		});
	}

	/**
	 * 显示offfer界面
	 * 
	 * @param context
	 * @param replaceTip
	 *            不显示offer的情况下的替换文�?
	 * 
	 * @param confimTip
	 *            确认提示的文本，为null则不做提�?
	 */
	public static void showOffer(final Context context, final String replaceTip, final String confimTip)
	{
		MainActivity.instance.runOnUiThread(new Runnable()
		{
			@Override
			public void run()
			{
				if (confimTip != null)
				{
					AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.instance).setTitle("提示").setMessage(confimTip)
							.setPositiveButton("免费赚取", new DialogInterface.OnClickListener()
							{
								public void onClick(DialogInterface dialog, int which)
								{
									offerClient.showOffer(context);
								}
							}).setNegativeButton("取消", new DialogInterface.OnClickListener()
							{
								public void onClick(DialogInterface dialog, int which)
								{
									return;
								}
							}).setCancelable(false).create(); 
					alertDialog.show();
				}
				else
				{
					offerClient.showOffer(context);
				}
			}
		});
	}
}
